package com.color.admin.system.entity;


import com.color.admin.common.core.constant.Constant;
import com.color.admin.common.core.constant.ConstantData;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.v3.oas.annotations.media.Schema;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.Objects;
import java.util.Set;

/**
 * @author HaiQiu
 * @date 2021/12/22
 * 角色实体类
 */
@Entity
@Table(name = ConstantData.DEPT_TABLE, schema = ConstantData.SOURCE)
public class SysDept extends BaseEntity implements Serializable {

    @Schema(example = "xxxx",description = "主键ID")
    @NotEmpty(message = "ID"+ Constant.NOT_EMPTY,groups = update.class)
    private String id;

    @Schema(example = "0",description = "父级ID,默认0顶级")
    private String parentId;

    @Schema(example = "成都技术部",description = "部门名称")
    @NotEmpty(message = "名称"+ Constant.NOT_EMPTY)
    @Size(max = 20,message = "部门名称长度应该在1-20个字符之间")
    private String deptName;

    @Schema(description = "图标")
    @Size(max = 1000,message = "图标地址长度应该在1-1000个字符之间")
    private String icon;

    @Schema(example = "公司开发技术项目部门",description = "描述")
    @Size(max = 500,message = "描述长度应该在1-500个字符之间")
    private String description;

    @Schema(description = "jpa关联用户",hidden = true)
    public Set<SysUser> users;


    public void setId(String id) {
        this.id = id;
    }

    @Id
    @Column(name = "id",length = 500)
    @GeneratedValue(generator="id")
    @GenericGenerator(name="id", strategy="org.hibernate.id.UUIDGenerator")
    public String getId() {
        return id;
    }

    @Column(name = "parent_id",length = 500)
    public String getParentId() {
        return parentId;
    }

    public void setParentId(String parentId) {
        this.parentId = parentId;
    }

    @Column(name = "dept_name",length = 20)
    public String getDeptName() {
        return deptName;
    }

    public void setDeptName(String deptName) {
        this.deptName = deptName;
    }

    @Basic
    @Column(name = "icon",length = 1000)
    public String getIcon() {
        return icon;
    }

    public void setIcon(String icon) {
        this.icon = icon;
    }

    @Column(name = "description",length = 500)
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @OneToMany(mappedBy = "dept")
    public Set<SysUser> getUsers() {
        return users;
    }

    @JsonIgnore
    public void setUsers(Set<SysUser> userSet) {
        this.users = userSet;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (!(o instanceof SysDept)) {
            return false;
        }
        SysDept sysDept = (SysDept) o;
        return Objects.equals(getId(), sysDept.getId()) && Objects.equals(getParentId(), sysDept.getParentId()) && Objects.equals(getDeptName(), sysDept.getDeptName()) && Objects.equals(getIcon(), sysDept.getIcon()) && Objects.equals(getDescription(), sysDept.getDescription()) && Objects.equals(getSort(), sysDept.getSort()) && Objects.equals(getActive(), sysDept.getActive()) && Objects.equals(getCreateTime(), sysDept.getCreateTime()) && Objects.equals(getUpdateTime(), sysDept.getUpdateTime()) && Objects.equals(getUsers(), sysDept.getUsers());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getId(), getParentId(), getDeptName(), getIcon(), getDescription(), getSort(), getActive(), getCreateTime(), getUpdateTime(), getUsers());
    }
}
